Add TAL-Reverb-II plugin to test
[juce-lv2.git] / juce / source / extras / the jucer / src / model / paintelements / jucer_PaintElementRoundedRectangle.h
blobe29eba8931f39af83deea006a0a6160c717ea37c
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #ifndef __JUCER_PAINTELEMENTROUNDEDRECTANGLE_JUCEHEADER__
27 #define __JUCER_PAINTELEMENTROUNDEDRECTANGLE_JUCEHEADER__
29 #include "jucer_ColouredElement.h"
32 //==============================================================================
33 /**
35 class PaintElementRoundedRectangle : public ColouredElement
37 public:
38 //==============================================================================
39 PaintElementRoundedRectangle (PaintRoutine* owner)
40 : ColouredElement (owner, "Rounded Rectangle", true, false)
42 cornerSize = 10.0;
45 ~PaintElementRoundedRectangle() {}
47 //==============================================================================
48 void draw (Graphics& g, const ComponentLayout* layout, const Rectangle<int>& parentArea)
50 double x, y, w, h;
51 position.getRectangleDouble (x, y, w, h, parentArea, layout);
53 fillType.setFillType (g, getDocument(), parentArea);
54 g.fillRoundedRectangle ((float) x, (float) y, (float) w, (float) h, (float) cornerSize);
56 if (isStrokePresent)
58 strokeType.fill.setFillType (g, getDocument(), parentArea);
60 g.drawRoundedRectangle ((float) x, (float) y, (float) w, (float) h, (float) cornerSize,
61 getStrokeType().stroke.getStrokeThickness());
65 void getEditableProperties (Array <PropertyComponent*>& properties)
67 properties.add (new CornerSizeProperty (this));
69 ColouredElement::getEditableProperties (properties);
71 properties.add (new ShapeToPathProperty (this));
74 //==============================================================================
75 class SetCornerSizeAction : public PaintElementUndoableAction <PaintElementRoundedRectangle>
77 public:
78 SetCornerSizeAction (PaintElementRoundedRectangle* const element, const double newSize_)
79 : PaintElementUndoableAction <PaintElementRoundedRectangle> (element),
80 newSize (newSize_)
82 oldSize = element->getCornerSize();
85 bool perform()
87 showCorrectTab();
88 getElement()->setCornerSize (newSize, false);
89 return true;
92 bool undo()
94 showCorrectTab();
95 getElement()->setCornerSize (oldSize, false);
96 return true;
99 private:
100 double newSize, oldSize;
103 void setCornerSize (const double newSize, const bool undoable)
105 if (newSize != cornerSize)
107 if (undoable)
109 perform (new SetCornerSizeAction (this, newSize),
110 "Change rounded rectangle corner size");
112 else
114 cornerSize = newSize;
115 changed();
120 double getCornerSize() const throw() { return cornerSize; }
122 //==============================================================================
123 void fillInGeneratedCode (GeneratedCode& code, String& paintMethodCode)
125 if (! fillType.isInvisible())
127 String x, y, w, h, s;
128 positionToCode (position, code.document->getComponentLayout(), x, y, w, h);
130 fillType.fillInGeneratedCode (code, paintMethodCode);
131 s << "g.fillRoundedRectangle ("
132 << castToFloat (x) << ", "
133 << castToFloat (y) << ", "
134 << castToFloat (w) << ", "
135 << castToFloat (h) << ", "
136 << valueToFloat (cornerSize) << ");\n\n";
138 paintMethodCode += s;
141 if (isStrokePresent && ! strokeType.isInvisible())
143 String x, y, w, h, s;
144 positionToCode (position, code.document->getComponentLayout(), x, y, w, h);
146 strokeType.fill.fillInGeneratedCode (code, paintMethodCode);
147 s << "g.drawRoundedRectangle ("
148 << castToFloat (x) << ", "
149 << castToFloat (y) << ", "
150 << castToFloat (w) << ", "
151 << castToFloat (h) << ", "
152 << valueToFloat (cornerSize) << ", "
153 << valueToFloat (strokeType.stroke.getStrokeThickness()) << ");\n\n";
155 paintMethodCode += s;
159 static const char* getTagName() throw() { return "ROUNDRECT"; }
161 XmlElement* createXml() const
163 XmlElement* const e = new XmlElement (getTagName());
165 position.applyToXml (*e);
166 e->setAttribute ("cornerSize", cornerSize);
167 addColourAttributes (e);
169 return e;
172 bool loadFromXml (const XmlElement& xml)
174 if (xml.hasTagName (getTagName()))
176 position.restoreFromXml (xml, position);
177 cornerSize = xml.getDoubleAttribute ("cornerSize", 10.0);
178 loadColourAttributes (xml);
180 return true;
182 else
184 jassertfalse
185 return false;
189 void convertToPath()
191 double x, y, w, h;
192 getCurrentAbsoluteBoundsDouble (x, y, w, h);
194 Path path;
195 path.addRoundedRectangle ((float) x, (float) y, (float) w, (float) h, (float) cornerSize);
197 convertToNewPathElement (path);
200 private:
201 double cornerSize;
203 //==============================================================================
204 class CornerSizeProperty : public SliderPropertyComponent,
205 public ChangeListener
207 public:
208 CornerSizeProperty (PaintElementRoundedRectangle* const owner_)
209 : SliderPropertyComponent ("corner size", 1.0, 200.0, 0.5, 0.4),
210 owner (owner_)
212 owner->getDocument()->addChangeListener (this);
215 ~CornerSizeProperty()
217 owner->getDocument()->removeChangeListener (this);
220 void setValue (double newValue)
222 owner->getDocument()->getUndoManager().undoCurrentTransactionOnly();
224 owner->setCornerSize (newValue, true);
227 double getValue() const { return owner->getCornerSize(); }
229 void changeListenerCallback (ChangeBroadcaster*) { refresh(); }
231 private:
232 PaintElementRoundedRectangle* const owner;
235 //==============================================================================
236 class ShapeToPathProperty : public ButtonPropertyComponent
238 public:
239 ShapeToPathProperty (PaintElementRoundedRectangle* const element_)
240 : ButtonPropertyComponent ("path", false),
241 element (element_)
245 void buttonClicked()
247 element->convertToPath();
250 const String getButtonText() const
252 return "convert to a path";
255 private:
256 PaintElementRoundedRectangle* const element;
261 #endif // __JUCER_PAINTELEMENTROUNDEDRECTANGLE_JUCEHEADER__